//package Work;
//
//class DatabaseConnection implements Runnable {
//    public DatabaseConnection() {
//        System.out.println("连接已打开。");
//    }
//
//    @Override
//    public void run() {
//        System.out.println("连接已关闭。");
//    }
//}
//
//class ConnectionManager implements AutoCloseable {
//    private static final Cleaner cleaner = Cleaner.create();
//    private final Cleaner.Cleanable cleanable;
//    private final DatabaseConnection dbConnection;
//
//    public ConnectionManager() {
//        this.dbConnection = new DatabaseConnection();
//        this.cleanable = cleaner.register(this, dbConnection);
//    }
//
//    public void query() {
//        System.out.println("执行数据库查询...");
//    }
//
//    @Override
//    public void close() {
//        this.cleanable.clean();
//    }
//}
//
//public class Cleaner{
//    public static void main(String[] args) throws Exception {
//        try (ConnectionManager manager = new ConnectionManager()) {
//            manager.query();
//        }
//        System.gc();
//    }
//}
